package com.jiangxiaofei.citycloud.adapter;

import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jiangxiaofei.citycloud.R;
import com.jiangxiaofei.citycloud.bean.GoodListBean;

import java.util.List;

/**
 * @author : JiangXfei
 *         日期: 2017/10/19 0019
 *         物资交流商品列表适配器
 */

public class FreshGoodAdapter extends BaseQuickAdapter<GoodListBean, BaseViewHolder> {
    public FreshGoodAdapter(@LayoutRes int layoutResId, @Nullable List<GoodListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, GoodListBean item) {
        ImageView imgPhoto = helper.getView(R.id.img_good);
        String[] imgs = item.getImg().split(",");
        Glide.with(mContext)
                .load(imgs[0])
                .apply(RequestOptions.centerCropTransform()
                        .error(R.drawable.ic_no_pic)
                        .placeholder(R.drawable.ic_no_pic))
                .into(imgPhoto);
        helper.setText(R.id.tv_title, item.getTitle());
        String price = item.getPrice();
        int i = item.getPrice().indexOf(".");
        if (i > 0) {
            price = item.getPrice().substring(0, i+2);
        }
        helper.setText(R.id.tv_price, price);
        helper.setText(R.id.tv_addtime, item.getIssue());
    }

}
